UCID : 12149052
Name : Regina Widjaya
CLOROPLETH MAP 1
## OGR data source with driver: ESRI Shapefile
## Source: "ne_50m_admin_1_states_provinces_lakes", layer: "ne_50m_admin_1_states_provinces_lakes"
## with 100 features
## It has 40 fields
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
## [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
m <- ggplot(h1b_state, aes(long, lat, group=group, fill= perc_diff)) +
#geom_text(aes(long, lat, group = NULL, label = h1b_state$h1b_1000), size = 2) +
geom_polygon() +
#geom_text(aes(long, lat, label = scales::percent(h1b_state$perc_diff)), color = "white") +
coord_map("albers", lat0 = 29.5, lat1 = 45.5,
xlim = c(-124.85, -66.88), ylim = c(24.4, 49.38),
orientation = c(90, 0, -98.35)) +
labs(title="H1-B median wage is being paid MUCH MORE than host state median wage...",
subtitle="Percent Difference in Median Wage (Local State vs. H1-B)",
caption="Source: USCIS",
y="Latitude",
x= "Longitude") +
guides(fill=guide_legend(title="--% Higher")) +
scale_fill_viridis("perc_diff", labels= scales::percent, direction = -1) +
geom_path(color="white") +
theme(legend.position = "bottom",
axis.title.x= element_text(family = 'Courier New', face = 'bold', size = 10),
axis.text.x = element_text(angle = 0, hjust = 1, family = 'Andale Mono', size = 8),
axis.title.y = element_text(family = 'Courier New', face = 'bold', size = 10),
axis.text.y = element_text(angle = 0, hjust = 1, family = 'Andale Mono', size = 8),
panel.background=element_rect(fill="#f7f7f7"),
plot.background=element_rect(fill="#f7f7f7"),
strip.background = element_rect(fill="#f7f7f7"),
legend.background = element_rect(fill="#f7f7f7"),
plot.title = element_text(family = 'Courier New', hjust = 0, face = "bold", size = 15),
plot.subtitle = element_text(family = 'Courier New', face = "italic", size = 10),
plot.caption = element_text(family = 'Courier New', face = "italic", size = 9),
panel.grid.major.x=element_line(color="gray100"),
panel.grid.minor.x=element_line(color="gray90")
)
plot(m)

CLOROPLETH MAP 2
m2 <- ggplot(h1b_state, aes(long, lat, group=group, fill= perc_diff_CM)) +
#geom_text(aes(long, lat, group = NULL, label = h1b_state$h1b_1000), size = 2) +
geom_polygon() +
#geom_text(aes(long, lat, label = scales::percent(h1b_state$perc_diff)), color = "white") +
coord_map("albers", lat0 = 29.5, lat1 = 45.5,
xlim = c(-124.85, -66.88), ylim = c(24.4, 49.38),
orientation = c(90, 0, -98.35)) +
labs(title="However, H1-B wage are still less than \nmedian Computer & Mathematics wage...",
subtitle="Percent Difference in Median Wage (Local State vs. H1-B)",
caption="Source: USCIS",
y="Latitude",
x= "Longitude") +
guides(fill=guide_legend(title="--% Higher")) +
scale_fill_viridis("perc_diff", option = "magma", labels= scales::percent) +
geom_path(color="white") +
theme(legend.position = "bottom",
axis.title.x= element_text(family = 'Courier New', face = 'bold', size = 10),
axis.text.x = element_text(angle = 0, hjust = 1, family = 'Andale Mono', size = 8),
axis.title.y = element_text(family = 'Courier New', face = 'bold', size = 10),
axis.text.y = element_text(angle = 0, hjust = 1, family = 'Andale Mono', size = 8),
panel.background=element_rect(fill="#f7f7f7"),
plot.background=element_rect(fill="#f7f7f7"),
strip.background = element_rect(fill="#f7f7f7"),
legend.background = element_rect(fill="#f7f7f7"),
plot.title = element_text(family = 'Courier New', hjust = 0, face = "bold", size = 15),
plot.subtitle = element_text(family = 'Courier New', face = "italic", size = 10),
plot.caption = element_text(family = 'Courier New', face = "italic", size = 9),
panel.grid.major.x=element_line(color="gray100"),
panel.grid.minor.x=element_line(color="gray90")
)
plot(m2)

INTERACTIVE MAP (PLOTLY)
intr_df <- h1b_state[,c("name","total_h1b","median_wage","h1b_1000","perc_diff","perc_diff_CM", "pop_company", "postal")]
intr_df <-unique(intr_df)
intr_df$perc_diff <- scales::percent(intr_df$perc_diff)
intr_df$perc_diff_CM <- scales::percent(intr_df$perc_diff_CM)
intr_df$hover <- with(intr_df, paste(name, '<br>',
"# of Approved H1-B", total_h1b, '<br>',
"Median Wage", median_wage, "<br>",
"*", perc_diff,"Above State Median Wage","<br>",
"*", perc_diff_CM,"Above State C&M Wage","<br>",
"Biggest Sponsor:", pop_company))
# give state boundaries a white border
l <- list(color = toRGB("white"), width = 2)
# specify some map projection/options
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
pl <- plot_ly(intr_df, z = intr_df$total_h1b, text = intr_df$hover, locations = intr_df$postal, type = 'choropleth',
locationmode = 'USA-states', color = intr_df$total_h1b, colors = 'Purples',
marker = list(line = l), colorbar = list(title = "# of Approved H1-B Application")) %>%
layout(title = '2016 H1-B Approved Application Summary<br>(Hover for breakdown | Source: USCIS)',
caption = 'Source: USCIS' , geo = g)
pl